<?php
/* ************************************************
 * Copyright Reserved @ Compass Technology       **
 * @Procedure: Shared module for merchant_my lists  **
 * @Designer: Liang Fan                          **
 * @Date: 18 Feb, 2012                           **
 * ************************************************/

/*
 * Deal with the ranking list
 * Author:Cavin Date:Oct 30,2011
 
 * Bug fixed by Liang Fan on 9/2/2012: Users in block list and delete list can't be shown here
 
 */

$sql = "SELECT a.usr_shw_name ,a.temp_userid, a.usr_id, a.hits, b.temp_userid, b.acc_status FROM `org_details` a, `org_firststep` b  WHERE 1=1 and b.acc_status <> 10 and b.acc_status <> 9 and a.temp_userid=b.temp_userid  ORDER BY `hits` DESC LIMIT 0,10";
$rest = $db -> executeQuery($sql);
if($rest)
{
	$body = '';
	$j = 0;
	foreach ($rest as $val)
	{
		$j++;
		if($j <= 5)
		{
			$body .= "<tr><td valign='top' class='ranklist' width='10%'><span class='top_seq'>".$j."</span></td><td width='70%' class='top_items'><a href='".buildMemVisitedURL($val['temp_userid'],$val['usr_shw_name'],'1')."' title='".$val['usr_shw_name']."'>". subString($val['usr_shw_name'],0,15)."</a></td><td width='20%' align='right' valign='top' class='top_items'>".$val['hits']."</td></tr>";
		}
		else 
		{
			$body .= "<tr><td valign='top' class='ranklist' width='10%'><span class='down_seq'>".$j."</span></td><td width='70%' class='down_items'><a href='".buildMemVisitedURL($val['temp_userid'],$val['usr_shw_name'],'1')."' title='".$val['usr_shw_name']."'>". subString($val['usr_shw_name'],0,15)."</a></td><td width='20%' align='right' valign='top' class='down_items'>".$val['hits']."</td></tr>";
		}
	}
	$zTemplate -> set_var('highHits',$body);
}

/*Bug fixed by Liang, don't show blocked users and deleted users*/

$sql = "SELECT COUNT(*) AS total ,fds_id FROM `usr_relationship` where fds_id in  
(SELECT `usr_id` from `org_details` where `temp_userid` in (SELECT `temp_userid` FROM `org_firststep` WHERE `acc_status` <> 10 and `acc_status` <> 9))
GROUP BY `fds_id` ORDER BY `total` DESC LIMIT 0,10";

$rs = $db -> executeQuery($sql);
if($rs)
{
	$body = '';
	$j=0;
	foreach ($rs as $val)
	{
		$nickName = getUsrNickName($val['fds_id']);
		$val['temp_userid'] = getTempUserId($val['fds_id']);
		if($nickName == '') continue;
		$j++;
		if($j <= 5)
		{
			$body .= "<tr><td valign='top' class='ranklist' width='10%'><span class='top_seq'>".$j."</span></td><td width='70%' class='top_items'><a href='".buildMemVisitedURL($val['temp_userid'],$nickName,'1')."' title='".$nickName."'>". subString($nickName,0,15)."</a></td><td width='20%' align='right' valign='top' class='top_items'>".$val['total']."</td></tr>";
		}
		else 
		{
			$body .= "<tr><td valign='top' class='ranklist' width='10%'><span class='down_seq'>".$j."</span></td><td width='70%' class='down_items'><a href='".buildMemVisitedURL($val['temp_userid'],$nickName,'1')."' title='".$nickName."'>". subString($nickName,0,15)."</a></td><td width='20%' align='right' valign='top' class='down_items'>".$val['total']."</td></tr>";
		}
	}
	$zTemplate -> set_var('highFollowers',$body);
}
?>